// import com.alibaba.druid.DbType;
// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.SQLName;
// import com.alibaba.druid.sql.ast.SQLObject;
// import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement;
// import com.alibaba.druid.sql.ast.statement.SQLExternalRecordFormat;
// import com.alibaba.druid.sql.dialect.oracle.ast.OracleSQLObject;
// import com.alibaba.druid.sql.dialect.oracle.ast.OracleSegmentAttributes;
// import com.alibaba.druid.sql.dialect.oracle.ast.OracleSegmentAttributesImpl;
// import com.alibaba.druid.sql.dialect.oracle.ast.clause.OracleLobStorageClause;
// import com.alibaba.druid.sql.dialect.oracle.ast.clause.OracleStorageClause;
// import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "OracleCreateTableStatement.h"
#include "../../../../ast/statement/SQLExternalRecordFormat.h"
#include "../../../../ast/statement/SQLExprTableSource.h"
#include "../../../../ast/statement/SQLSelect.h"
#include "../../../../ast/SQLExpr.h"
#include "../../../../ast/SQLName.h"
#include "../../../../ast/SQLObject.h"
#include "../../../../ast/SQLPartitionBy.h"
#include "../clause/OracleLobStorageClause.h"
#include "../clause/OracleStorageClause.h"
#include "../../visitor/OracleASTVisitor.h"
#include "../../../../visitor/SQLASTVisitor.h"
#include "OracleXmlColumnProperties.h"
#include "../../../../../utils/listTran.h"

OracleCreateTableStatement_DeferredSegmentCreation_ptr OracleCreateTableStatement_DeferredSegmentCreation::IMMEDIATE = OracleCreateTableStatement_DeferredSegmentCreation_ptr(new OracleCreateTableStatement_DeferredSegmentCreation(1ULL << 0, make_string_ptr("IMMEDIATE")));
OracleCreateTableStatement_DeferredSegmentCreation_ptr OracleCreateTableStatement_DeferredSegmentCreation::DEFERRED = OracleCreateTableStatement_DeferredSegmentCreation_ptr(new OracleCreateTableStatement_DeferredSegmentCreation(1ULL << 1, make_string_ptr("DEFERRED")));

OracleCreateTableStatement_DeferredSegmentCreation::OracleCreateTableStatement_DeferredSegmentCreation(uint64_t mask, string_ptr name)
{
  this->mask = mask;
  this->name = name;
}

OracleCreateTableStatement_Organization::OracleCreateTableStatement_Organization()
{
  externalDirectoryLocation = std::make_shared<std::list<SQLExpr_ptr>>();
}
void OracleCreateTableStatement_Organization::accept0(SQLASTVisitor_ptr visitor)
{
  this->accept0(std::dynamic_pointer_cast<OracleASTVisitor>(visitor));
}

void OracleCreateTableStatement_Organization::accept0(OracleASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(OracleCreateTableStatement_Organization)))
  {
    acceptChild(visitor, tablespace);
    acceptChild(visitor, storage);
  }
  visitor->endVisit(SharedObject(OracleCreateTableStatement_Organization));
}

string_ptr OracleCreateTableStatement_Organization::getType()
{
  return type;
}

void OracleCreateTableStatement_Organization::setType(string_ptr type)
{
  this->type = type;
}

SQLName_ptr OracleCreateTableStatement_Organization::getExternalType()
{
  return externalType;
}

void OracleCreateTableStatement_Organization::setExternalType(SQLName_ptr externalType)
{
  this->externalType = externalType;
}

SQLExpr_ptr OracleCreateTableStatement_Organization::getExternalDirectory()
{
  return externalDirectory;
}

void OracleCreateTableStatement_Organization::setExternalDirectory(SQLExpr_ptr externalDirectory)
{
  this->externalDirectory = externalDirectory;
}

SQLExternalRecordFormat_ptr OracleCreateTableStatement_Organization::getExternalDirectoryRecordFormat()
{
  return externalDirectoryRecordFormat;
}

void OracleCreateTableStatement_Organization::setExternalDirectoryRecordFormat(SQLExternalRecordFormat_ptr recordFormat)
{
  if (recordFormat != nullptr)
  {
    recordFormat->setParent(SharedObject(OracleCreateTableStatement_Organization));
  }
  this->externalDirectoryRecordFormat = recordFormat;
}

SQLExpr_ptr OracleCreateTableStatement_Organization::getExternalRejectLimit()
{
  return externalRejectLimit;
}

void OracleCreateTableStatement_Organization::setExternalRejectLimit(SQLExpr_ptr externalRejectLimit)
{
  if (externalRejectLimit != nullptr)
  {
    externalRejectLimit->setParent(SharedObject(OracleCreateTableStatement_Organization));
  }
  this->externalRejectLimit = externalRejectLimit;
}

SQLExpr_list_ptr OracleCreateTableStatement_Organization::getExternalDirectoryLocation()
{
  return externalDirectoryLocation;
}

// @Override
void OracleCreateTableStatement_OIDIndex::accept0(OracleASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(OracleCreateTableStatement_OIDIndex)))
  {
    acceptChild(visitor, name);
    acceptChild(visitor, tablespace);
    acceptChild(visitor, storage);
  }
  visitor->endVisit(SharedObject(OracleCreateTableStatement_OIDIndex));
}

void OracleCreateTableStatement_OIDIndex::accept0(SQLASTVisitor_ptr visitor)
{
  accept0(std::dynamic_pointer_cast<OracleASTVisitor>(visitor));
}

SQLName_ptr OracleCreateTableStatement_OIDIndex::getName()
{
  return name;
}

void OracleCreateTableStatement_OIDIndex::setName(SQLName_ptr name)
{
  if (name != nullptr)
  {
    name->setParent(SharedObject(OracleCreateTableStatement_OIDIndex));
  }
  this->name = name;
}

void OracleCreateTableStatement::simplify()
{
  tablespace = nullptr;
  storage = nullptr;
  lobStorage = nullptr;

  pctfree = 0;
  pctused = 0;
  initrans = 0;
  maxtrans = 0;
  pctincrease = 0;

  logging = BOOL::FALSE;
  compress = BOOL::FALSE;
  compressLevel = 0;
  compressForOltp = BOOL::FALSE;

  onCommitPreserveRows = BOOL::FALSE;
  onCommitDeleteRows = BOOL::FALSE;

  SQLCreateTableStatement::simplify();
}

OracleCreateTableStatement::OracleCreateTableStatement()
    : SQLCreateTableStatement(DbType_ptr(new DbType(&DbType::oracle)))
{
  clusterColumns = std::make_shared<std::list<SQLName_ptr>>();
  including = std::make_shared<std::list<SQLName_ptr>>();
}

OracleLobStorageClause_ptr OracleCreateTableStatement::getLobStorage()
{
  return lobStorage;
}

void OracleCreateTableStatement::setLobStorage(OracleLobStorageClause_ptr lobStorage)
{
  this->lobStorage = lobStorage;
}

OracleCreateTableStatement_DeferredSegmentCreation_ptr OracleCreateTableStatement::getDeferredSegmentCreation()
{
  return deferredSegmentCreation;
}

void OracleCreateTableStatement::setDeferredSegmentCreation(OracleCreateTableStatement_DeferredSegmentCreation_ptr deferredSegmentCreation)
{
  this->deferredSegmentCreation = deferredSegmentCreation;
}

BOOL_ptr OracleCreateTableStatement::getCache()
{
  return cache;
}

void OracleCreateTableStatement::setCache(BOOL_ptr cache)
{
  this->cache = cache;
}

BOOL_ptr OracleCreateTableStatement::isOnCommitDeleteRows()
{
  return onCommitDeleteRows;
}

void OracleCreateTableStatement::setOnCommitDeleteRows(BOOL_ptr onCommitDeleteRows)
{
  this->onCommitDeleteRows = onCommitDeleteRows;
}

int OracleCreateTableStatement::getCompressLevel()
{
  return compressLevel;
}

void OracleCreateTableStatement::setCompressLevel(int compressLevel)
{
  this->compressLevel = compressLevel;
}

int OracleCreateTableStatement::getPctfree()
{
  return pctfree;
}

void OracleCreateTableStatement::setPctfree(int pctfree)
{
  this->pctfree = pctfree;
}

int OracleCreateTableStatement::getPctused()
{
  return pctused;
}

void OracleCreateTableStatement::setPctused(int pctused)
{
  this->pctused = pctused;
}

int OracleCreateTableStatement::getInitrans()
{
  return initrans;
}

void OracleCreateTableStatement::setInitrans(int initrans)
{
  this->initrans = initrans;
}

int OracleCreateTableStatement::getMaxtrans()
{
  return maxtrans;
}

void OracleCreateTableStatement::setMaxtrans(int maxtrans)
{
  this->maxtrans = maxtrans;
}

int OracleCreateTableStatement::getPctincrease()
{
  return pctincrease;
}

void OracleCreateTableStatement::setPctincrease(int pctincrease)
{
  this->pctincrease = pctincrease;
}

BOOL_ptr OracleCreateTableStatement::getParallel()
{
  return parallel;
}

void OracleCreateTableStatement::setParallel(BOOL_ptr parallel)
{
  this->parallel = parallel;
}

SQLExpr_ptr OracleCreateTableStatement::getParallelValue()
{
  return parallelValue;
}

void OracleCreateTableStatement::setParallelValue(SQLExpr_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(OracleCreateTableStatement));
  }
  this->parallelValue = x;
}

BOOL_ptr OracleCreateTableStatement::isCursorSpecificSegment()
{
  return cursorSpecificSegment;
}

void OracleCreateTableStatement::setCursorSpecificSegment(BOOL_ptr cursorSpecificSegment)
{
  this->cursorSpecificSegment = cursorSpecificSegment;
}

BOOL_ptr OracleCreateTableStatement::isInMemoryMetadata()
{
  return inMemoryMetadata;
}

void OracleCreateTableStatement::setInMemoryMetadata(BOOL_ptr inMemoryMetadata)
{
  this->inMemoryMetadata = inMemoryMetadata;
}

void OracleCreateTableStatement::accept0(SQLASTVisitor_ptr visitor)
{
  accept0(std::dynamic_pointer_cast<OracleASTVisitor>(visitor));
}

SQLObject_ptr OracleCreateTableStatement::getStorage()
{
  return storage;
}

void OracleCreateTableStatement::setStorage(SQLObject_ptr storage)
{
  if (storage != nullptr)
  {
    storage->setParent(SharedObject(OracleCreateTableStatement));
  }
  this->storage = std::dynamic_pointer_cast<OracleStorageClause>(storage);
}

SQLName_ptr OracleCreateTableStatement::getOf()
{
  return of;
}

void OracleCreateTableStatement::setOf(SQLName_ptr of)
{
  if (of != nullptr)
  {
    of->setParent(SharedObject(OracleCreateTableStatement));
  }
  this->of = of;
}

OracleCreateTableStatement_OIDIndex_ptr OracleCreateTableStatement::getOidIndex()
{
  return oidIndex;
}

void OracleCreateTableStatement::setOidIndex(OracleCreateTableStatement_OIDIndex_ptr oidIndex)
{
  if (oidIndex != nullptr)
  {
    oidIndex->setParent(SharedObject(OracleCreateTableStatement));
  }
  this->oidIndex = oidIndex;
}

BOOL_ptr OracleCreateTableStatement::isMonitoring()
{
  return monitoring;
}

void OracleCreateTableStatement::setMonitoring(BOOL_ptr monitoring)
{
  this->monitoring = monitoring;
}

BOOL_ptr OracleCreateTableStatement::isCompressForOltp()
{
  return compressForOltp;
}

void OracleCreateTableStatement::setCompressForOltp(BOOL_ptr compressForOltp)
{
  this->compressForOltp = compressForOltp;
}

BOOL_ptr OracleCreateTableStatement::getEnableRowMovement()
{
  return enableRowMovement;
}

void OracleCreateTableStatement::setEnableRowMovement(BOOL_ptr enableRowMovement)
{
  this->enableRowMovement = enableRowMovement;
}

SQLName_list_ptr OracleCreateTableStatement::getClusterColumns()
{
  return clusterColumns;
}

SQLName_ptr OracleCreateTableStatement::getCluster()
{
  return cluster;
}

void OracleCreateTableStatement::setCluster(SQLName_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(OracleCreateTableStatement));
  }
  this->cluster = x;
}

SQLName_list_ptr OracleCreateTableStatement::getIncluding()
{
  return including;
}

OracleCreateTableStatement_Organization_ptr OracleCreateTableStatement::getOrganization()
{
  return organization;
}

void OracleCreateTableStatement::setOrganization(OracleCreateTableStatement_Organization_ptr organization)
{
  if (organization != nullptr)
  {
    organization->setParent(SharedObject(OracleCreateTableStatement));
  }
  this->organization = organization;
}

void OracleCreateTableStatement::accept0(OracleASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(OracleCreateTableStatement)))
  {
    this->SQLObjectImpl::acceptChild(visitor, tableSource);
    this->SQLObjectImpl::acceptChild(visitor, of);
    SQLObject_list_ptr tmp1 = ListTran::tran_class<SQLTableElement, SQLObject>(tableElementList);
    this->SQLObjectImpl::acceptChild(visitor, tmp1);
    this->SQLObjectImpl::acceptChild(visitor, tablespace);
    this->SQLObjectImpl::acceptChild(visitor, select);
    this->SQLObjectImpl::acceptChild(visitor, storage);
    this->SQLObjectImpl::acceptChild(visitor, partitioning);
  }
  visitor->endVisit(SharedObject(OracleCreateTableStatement));
}

OracleXmlColumnProperties_ptr OracleCreateTableStatement::getXmlTypeColumnProperties()
{
  return xmlTypeColumnProperties;
}

void OracleCreateTableStatement::setXmlTypeColumnProperties(OracleXmlColumnProperties_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(OracleCreateTableStatement));
  }
  this->xmlTypeColumnProperties = x;
}
